package org.apache.servicecomb.fence.resource;

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.jdbc.JDBCClient;
import org.springframework.stereotype.Component;

@Component
public class VertxJdbcConfig {
    private static JDBCClient jdbcClient;
    private static JsonObject config;
    private static VertxJdbcConfig jdbcConfig;

    static {
        config = new JsonObject();
        config.put("url", "jdbc:opengauss://113.45.169.21:8000/postgres?currentSchema=authentication_server_db");
        config.put("driver_class", "org.opengauss.Driver");
        config.put("user", "root");
        config.put("password", "Htbnd2001");
    }

    public static VertxJdbcConfig create(Vertx vertx){
        if (jdbcClient == null){
            synchronized (VertxJdbcConfig.class) {
                jdbcConfig = new VertxJdbcConfig();
                jdbcConfig.init(vertx);
            }
        }
        return jdbcConfig;
    }

    private void init(Vertx vertx) {
        jdbcClient = JDBCClient.createShared(vertx, config);
    }

    public JDBCClient getJdbcClient(){
        return jdbcClient;
    }


}

